﻿<script src="/LiberUI/Scripts/jquery.js"></script>
<script src="/LiberUI/Scripts/LiberUI.Base.js"></script>
<script src="/LiberUI/Scripts/LiberUI.js"></script>
<script src="/LiberUI/Scripts/LiberUI.Action.js"></script>
<script src="/LiberUI/Scripts/LiberUI.js"></script>
<link href="/SiteUI/Sale/wgOrderSummy.css" rel="stylesheet" />

<div class="col-lg-12">
    <div class="wg-sale-ordercounter new">
        <a class="LinkBlock" href="/Sale/Orders?status=pending">
            <div class="total-wraper">
                <span class="total">-</span>
            </div>
            <h5 class="title">待确认</h5>
            <div class="lnk">
                <i class="soicon icon-navigatenext"></i>
            </div>
        </a>
    </div>  
    <div class="wg-sale-ordercounter todelivery">
        <a class="LinkBlock"  href="/Sale/Orders?flag=toDelivery">
            <div class="total-wraper">
                <span class="total">-</span>
            </div>
            <h5 class="title">待发货</h5>
            <div class="lnk">
                <i class="soicon icon-navigatenext"></i>
            </div>
        </a>

    </div>
    <div class="wg-sale-ordercounter tostockin">
        <a class="LinkBlock"  href="/Sale/Orders?flag=toStockIn">
            <div class="total-wraper">
                <span class="total">-</span>
            </div>
            <h5 class="title">待入库</h5>
            <div class="lnk">
                <i class="soicon icon-navigatenext"></i>
            </div>
        </a>

    </div>
    <div class="wg-sale-ordercounter topay">
        <a class="LinkBlock"  href="/Sale/Orders?flag=toPay">
            <div class="total-wraper">
                <span class="total">-</span>
            </div>
            <h5 class="title">待付款</h5>
            <div class="lnk">
                <i class="soicon icon-navigatenext"></i>
            </div>
        </a>

    </div>
</div>

<script>
    var wgOrderSummy = {
        cards: [
        {
            cnd: {
                onlymine:false,
                status:'pending'
            },
            data:null,
            update: function () {
                $(".wg-sale-ordercounter.new").find(".total").vl(this.data.Total).hide().slideDown();
            }
        },
        {
            cnd: {
                onlymine: false,
                flag: 'toDelivery'
            },
            data: null,
            update: function () {
                $(".wg-sale-ordercounter.todelivery").find(".total").vl(this.data.Total).hide().slideDown();
            }
            
        },
        {
            cnd: {
                onlymine: false,
                flag:'toStockIn'
            },
            data: null,
            update: function () {
                $(".wg-sale-ordercounter.tostockin").find(".total").vl(this.data.Total).hide().slideDown();
            }
        },
        {
            cnd: {
                onlymine: false,
                flag:'toPay'
            },
            data: null,
            update: function () {
                $(".wg-sale-ordercounter.topay").find(".total").vl('-').hide().slideDown();
            }
        }],
        update: function () {
            if (User.DataRange.onlymine) {
                $(".wg-sale-ordercounter>a").each(function () {
                    $(this).attr("href", $(this).attr("href").replace("/Orders", "/MyOrders"));
                })
            }
            else {
                $(".wg-sale-ordercounter>a").each(function () {
                    $(this).attr("href", $(this).attr("href").replace("/MyOrders", "/Orders"));
                })
            }

            wgOrderSummy.cards.forEach(function (c) {
                c.cnd.onlymine = User.DataRange.onlymine;
                $.getJSON("/Sale/CountOrders", c.cnd, function (rtn) {
                    if (rtn.IsPositive) {
                        c.data = rtn.Data;
                        c.update();
                    }
                });
            });
            setTimeout(wgOrderSummy.update, 120000);
        }

    }
    $(function () {
        if (User) {
            wgOrderSummy.update();
        }
        else {
            $("body").on("UserReady", wgOrderSummy.update);
        }
        $("body").on("DataRangeChanged", wgOrderSummy.update);
    })
</script>
